package org.jarraiders.musiclibrary.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasMouseOverHandlers;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class TracksIcon extends Composite implements HasText, HasMouseOverHandlers {
	private TracksPopupPanel popupPanel;
	private static TracksIconUiBinder uiBinder = GWT.create(TracksIconUiBinder.class);

	interface TracksIconUiBinder extends UiBinder<Widget, TracksIcon> {
	}

	@UiField
	Label trackLabel;

	public TracksIcon() {
		popupPanel = new TracksPopupPanel();
		trackLabel = new Label();		
		initWidget(uiBinder.createAndBindUi(this));

	}

	public void setText(String text) {
		trackLabel.setText(text);
	}

	public String getText() {
		return trackLabel.getText();
	}

	public void setPopupVisible() {

		popupPanel.setVisible(true);
		popupPanel.setPopupPosition(this.getAbsoluteLeft() + 50, this.getAbsoluteTop() + 10);
		popupPanel.show();
	}

	public void setPopupUnvisible() {
		popupPanel.setVisible(false);		
		popupPanel.hide();
	}

	@Override
	public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
		return addDomHandler(handler, MouseOverEvent.getType());
	}
}
